<script type="text/javascript" src="<?php echo $this->baseUrl . '/public/' . $this->module; ?>/js/jRating.jquery.js"></script>
<link href="<?php echo $this->baseUrl . '/public/' . $this->module; ?>/css/jRating.jquery.css" rel="stylesheet" type="text/css" media="screen" />
<input type="hidden" id="id_item" value="<?php echo $this->id_item ?>">
<div class="hd_rating" style="<?php echo $this->position; ?>">
    <label>Your rate</label>
    <table id="rating">
        <tr>
            <td>Clean</td>
            <td><div class="type1" data-average="<?php if ($this->isRating) echo $this->rating['type1'];
else echo '0' ?>" data-id="type1"></div></td>
        </tr>
        <tr>
            <td>Location</td>
            <td><div class="type2" data-average="<?php if ($this->isRating) echo $this->rating['type2'];
else echo '0' ?>" data-id="type2"></div></td>
        </tr>
        <tr>
            <td>Facilities</td>
            <td><div class="type3" data-average="<?php if ($this->isRating) echo $this->rating['type3'];
else echo '0' ?>" data-id="type3"></div></td>
        </tr>
        <tr>
            <td>Overall</td>
            <td>
                <span id="overall"><?php if ($this->isRating) echo number_format($this->rating['overall'], 1, '.', ''); else echo '0.0' ?></span>
            </td>
        </tr>
         
        <tr>
            <td colspan="2" style="padding-right:123px;"><a href="#" id="comment" style="margin-top: 10px; background-color: #0896FF;" class="button">Feedback</a></td>
        </tr>
        
        
    </table>
</div>
<script type="text/javascript">
    var baseUrl = "<?php echo $this->baseUrl; ?>";
    var pathImg = "<?php echo $this->baseUrl . '/public/' . $this->module ?>";
    var itemName = "<?php echo $this->itemName; ?>";
    var isRating = <?php if ($this->isRating) echo $this->isRating; else echo 'false' ?>;
    var type1 = <?php if ($this->rating) echo $this->rating['type1']; else echo 0; ?>;
    var type2 = <?php if ($this->rating) echo $this->rating['type2']; else echo 0; ?>;
    var type3 = <?php if ($this->rating) echo $this->rating['type3']; else echo 0; ?>;
    $(document).ready(function() {
        var arr = {
            type: 'big',
            length: 10,
            canRateAgain: true,
            decimalLength: 1,
            showRateInfo:false,
            nbRates: 1
        };
        
        $(".type1").jRating(arr);
        $(".type2").jRating(arr);
        $(".type3").jRating(arr);
    });
    
    var boxyFeedback = new zm.Boxy({okButton: false, footer: false});
    boxyFeedback.setTitle('Comment');
    boxyFeedback.setContent('<textarea id="cmt" rows="5" style="width: 260px;" placeholder="Comment"></textarea>'
                + '<div style="clear:both;"></div>'
                + '<input style="margin-right: 80px;" class="button gray" type="button" name="save" id="feedback" value="Feedback">');

    $('#comment').click(function() {
        boxyFeedback.show();
    });
    $("#feedback").bind('click', function(){
        var comment = $("#cmt").val();
        if (type1 == 0 && type2 == 0 && type3 == 0)
             zm.Boxy.alert("Please rating for this hospital and submit again","Rating", 5000,{okButton: 'Close'});
         else if (comment && comment > 0 && comment < 250)
             zm.Boxy.alert("Your comment is not valid. Comment is not over 250 characters","Rating", 5000,{okButton: 'Close'});
        else {
            var id_item = $("#id_item").val();
            $.ajax({
                url : baseUrl + "/" + itemName + "/rating",
                type: "POST",
                data: { type1 : type1, type2 : type2, type3 : type3, comment : comment, id_item : id_item, isRating : isRating },
                dataType: "json",
                success: function(res){
                    if (res.error != "1") {
                        zm.Boxy.alert("Your feedback is recorded","Rating", 5000,{okButton: 'Close'});
                        window.location.reload();
                    } else {
                        zm.Boxy.alert("Server error. Please try again!","Rating", 5000,{okButton: 'Close'});
                    }
                }
            });
        }
    });
</script>